package com.heima.freemarker.controller;

import com.heima.freemarker.pojos.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Controller
public class FreemarkerController {


    @GetMapping("/hello")
    public String hello(Model model){

        //填充基本类型
        model.addAttribute("name","java58");

        //填充对象类型
        Student s1 = new Student("张三",20);
        model.addAttribute("stu",s1);

        //填充集合数据
        Student s2 = new Student("大宝",23);
        Student s3 = new Student("二宝",22);
        Student s4 = new Student("三宝",21);
        List<Student> list = new ArrayList<>();
        Collections.addAll(list,s2,s3,s4);
      model.addAttribute("stuList",list);


        return "01-demo";
    }
}
